{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ogr,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyspark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc = pyspark.SparkContext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "rdd = sc.textFile(\"./data/dltb.json\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 自定义过滤方法，如果最后一个字符是逗号，则去掉，然后解析json，取出空间部分，构建成几何要素，然后验证是否可用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "def MyFilter(line):\n",
    "    try:\n",
    "        if line[-1:] == \",\":\n",
    "            line = line[:-1]\n",
    "        dt = json.loads(line)\n",
    "        geojson = json.dumps(dt[\"geometry\"])\n",
    "        return ogr.CreateGeometryFromJson(geojson).IsValid()\n",
    "    except:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看原始rdd的前面六行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['{',\n",
       " '\"type\": \"FeatureCollection\",',\n",
       " '\"name\": \"dltb\",',\n",
       " '\"crs\": { \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:EPSG::3857\" } },',\n",
       " '\"features\": [',\n",
       " '{ \"type\": \"Feature\", \"id\": 0, \"properties\": { \"TBBH\": \"379\", \"DLMC\": \"旱地\", \"TBMJ\": 1489.7, \"Shape_Leng\": 1375.7685861499999, \"Shape_Area\": 47227.815217399999 }, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 11135971.080299999565, 2710491.250100001692772 ], [ 11135968.1246, 2710484.883000001311302 ], [ 11135961.2853, 2710475.23299999908 ], [ 11135951.616799999028, 2710465.415800001472235 ], [ 11135948.7961, 2710463.401999998837709 ], [ 11135948.193799998611, 2710461.321699999273 ], [ 11135956.735399998724, 2710450.2049 ], [ 11135957.76, 2710443.669399999082 ], [ 11135956.4021, 2710439.585 ], [ 11135952.13199999928, 2710436.7181 ], [ 11135946.85339999944, 2710436.924199998378754 ], [ 11135943.8612, 2710438.9107 ], [ 11135932.2478, 2710452.706300001591444 ], [ 11135928.322399999946, 2710457.997000001370907 ], [ 11135928.1552, 2710461.074 ], [ 11135929.367899999022, 2710463.464899998158216 ], [ 11135930.958799999207, 2710466.78099999949 ], [ 11135930.718299999833, 2710469.1651 ], [ 11135928.486699998379, 2710472.078499998897314 ], [ 11135925.651399999857, 2710473.219399999827 ], [ 11135921.9807, 2710473.048300001770258 ], [ 11135910.6939, 2710465.839699998497963 ], [ 11135908.4919, 2710462.3669 ], [ 11135908.504, 2710459.750799998641014 ], [ 11135912.5784, 2710455.30719999969 ], [ 11135915.4265, 2710451.3964 ], [ 11135915.4426, 2710447.934 ], [ 11135919.1299, 2710444.4888 ], [ 11135926.024, 2710442.289700001478195 ], [ 11135927.634799998254, 2710441.2969 ], [ 11135929.039, 2710435.3788 ], [ 11135927.700699999928, 2710427.062600001692772 ], [ 11135923.0689, 2710419.7313 ], [ 11135910.1994, 2710407.436900001019239 ], [ 11135901.6765, 2710398.009799998253584 ], [ 11135891.253299999982, 2710369.491799999028 ], [ 11135886.0993, 2710359.311099998652935 ], [ 11135882.4943, 2710344.982700001448393 ], [ 11135878.928399998695, 2710322.190699998289347 ], [ 11135876.7322, 2710300.943999998271465 ], [ 11135870.678899999708, 2710286.758099999279 ], [ 11135863.4026, 2710272.412500001490116 ], [ 11135853.8161, 2710261.441599998623133 ], [ 11135829.10909999907, 2710245.321600001305342 ], [ 11135807.7175, 2710239.989100001752377 ], [ 11135792.426199998707, 2710238.686299998313189 ], [ 11135763.622099999338, 2710248.3999 ], [ 11135739.9747, 2710267.678599998354912 ], [ 11135727.588599998504, 2710299.628899998962879 ], [ 11135714.5135, 2710348.195799998939037 ], [ 11135718.3693, 2710374.374699998646975 ], [ 11135728.987399999052, 2710393.814399998635054 ], [ 11135745.021, 2710432.977099999785 ], [ 11135763.813299998641, 2710471.075599998235703 ], [ 11135766.5482, 2710475.089499998837709 ], [ 11135777.856699999422, 2710477.6048 ], [ 11135800.2021, 2710475.247499998658895 ], [ 11135822.086399998516, 2710473.349599998444319 ], [ 11135833.691599998623, 2710477.866700001060963 ], [ 11135850.784499999136, 2710486.564599998295307 ], [ 11135859.96499999985, 2710486.146000001579523 ], [ 11135866.852299999446, 2710485.408799998462 ], [ 11135876.192899998277, 2710483.452100001275539 ], [ 11135885.97599999979, 2710485.0368 ], [ 11135887.9497, 2710488.277699999511 ], [ 11135885.9232, 2710496.4243 ], [ 11135876.51419999823, 2710513.15399999917 ], [ 11135861.4552, 2710527.702899999917 ], [ 11135838.7604, 2710539.4459 ], [ 11135821.300799999386, 2710543.826799999923 ], [ 11135799.121899999678, 2710543.261100001633167 ], [ 11135787.331599999219, 2710545.668000001460314 ], [ 11135778.42139999941, 2710553.782299999148 ], [ 11135776.703, 2710561.468699999154 ], [ 11135777.886799998581, 2710570.092 ], [ 11135785.4998, 2710577.8222 ], [ 11135792.034099999815, 2710587.239999998360872 ], [ 11135791.999899998307, 2710594.626600001007318 ], [ 11135787.83749999851, 2710601.532000001519918 ], [ 11135781.7, 2710605.504399999976 ], [ 11135764.693599998951, 2710611.118500001728535 ], [ 11135757.49599999934, 2710612.777499999851 ], [ 11135751.3092, 2710618.665699999779 ], [ 11135751.886199999601, 2710620.704199999571 ], [ 11135756.4697, 2710629.052799999714 ], [ 11135762.3581, 2710626.342500001192093 ], [ 11135771.8247, 2710624.699499998241663 ], [ 11135783.9367, 2710622.3508 ], [ 11135795.375399999321, 2710618.813700001686811 ], [ 11135812.5707, 2710613.006 ], [ 11135826.008299998939, 2710609.549800001084805 ], [ 11135851.452799998224, 2710603.026299998164177 ], [ 11135861.647199999541, 2710598.406100001186132 ], [ 11135867.913899999112, 2710594.055 ], [ 11135870.1077, 2710590.581399999559 ], [ 11135872.6108, 2710581.8321 ], [ 11135875.5995, 2710568.452399998903275 ], [ 11135877.586699999869, 2710563.255199998617172 ], [ 11135886.819899998605, 2710550.5513 ], [ 11135894.14499999955, 2710541.070199999958 ], [ 11135897.3896, 2710534.15509999916 ], [ 11135899.9545, 2710527.632199998944998 ], [ 11135903.672299999744, 2710518.5295 ], [ 11135908.056899998337, 2710512.2663 ], [ 11135915.550599999726, 2710504.9041 ], [ 11135925.9745, 2710497.0533 ], [ 11135933.9127, 2710493.9668 ], [ 11135943.2001, 2710492.466099999845 ], [ 11135960.657299999148, 2710491.794399999082 ], [ 11135971.080299999565, 2710491.250100001692772 ] ] ] } },']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdd.take(6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 原始RDD，一共有199行，那么看看有多少个要素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "199"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdd.count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 过滤掉之后，就剩下了192个要素了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "rdd2 = rdd.filter(lambda line : MyFilter(line))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "192"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdd2.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['{ \"type\": \"Feature\", \"id\": 0, \"properties\": { \"TBBH\": \"379\", \"DLMC\": \"旱地\", \"TBMJ\": 1489.7, \"Shape_Leng\": 1375.7685861499999, \"Shape_Area\": 47227.815217399999 }, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 11135971.080299999565, 2710491.250100001692772 ], [ 11135968.1246, 2710484.883000001311302 ], [ 11135961.2853, 2710475.23299999908 ], [ 11135951.616799999028, 2710465.415800001472235 ], [ 11135948.7961, 2710463.401999998837709 ], [ 11135948.193799998611, 2710461.321699999273 ], [ 11135956.735399998724, 2710450.2049 ], [ 11135957.76, 2710443.669399999082 ], [ 11135956.4021, 2710439.585 ], [ 11135952.13199999928, 2710436.7181 ], [ 11135946.85339999944, 2710436.924199998378754 ], [ 11135943.8612, 2710438.9107 ], [ 11135932.2478, 2710452.706300001591444 ], [ 11135928.322399999946, 2710457.997000001370907 ], [ 11135928.1552, 2710461.074 ], [ 11135929.367899999022, 2710463.464899998158216 ], [ 11135930.958799999207, 2710466.78099999949 ], [ 11135930.718299999833, 2710469.1651 ], [ 11135928.486699998379, 2710472.078499998897314 ], [ 11135925.651399999857, 2710473.219399999827 ], [ 11135921.9807, 2710473.048300001770258 ], [ 11135910.6939, 2710465.839699998497963 ], [ 11135908.4919, 2710462.3669 ], [ 11135908.504, 2710459.750799998641014 ], [ 11135912.5784, 2710455.30719999969 ], [ 11135915.4265, 2710451.3964 ], [ 11135915.4426, 2710447.934 ], [ 11135919.1299, 2710444.4888 ], [ 11135926.024, 2710442.289700001478195 ], [ 11135927.634799998254, 2710441.2969 ], [ 11135929.039, 2710435.3788 ], [ 11135927.700699999928, 2710427.062600001692772 ], [ 11135923.0689, 2710419.7313 ], [ 11135910.1994, 2710407.436900001019239 ], [ 11135901.6765, 2710398.009799998253584 ], [ 11135891.253299999982, 2710369.491799999028 ], [ 11135886.0993, 2710359.311099998652935 ], [ 11135882.4943, 2710344.982700001448393 ], [ 11135878.928399998695, 2710322.190699998289347 ], [ 11135876.7322, 2710300.943999998271465 ], [ 11135870.678899999708, 2710286.758099999279 ], [ 11135863.4026, 2710272.412500001490116 ], [ 11135853.8161, 2710261.441599998623133 ], [ 11135829.10909999907, 2710245.321600001305342 ], [ 11135807.7175, 2710239.989100001752377 ], [ 11135792.426199998707, 2710238.686299998313189 ], [ 11135763.622099999338, 2710248.3999 ], [ 11135739.9747, 2710267.678599998354912 ], [ 11135727.588599998504, 2710299.628899998962879 ], [ 11135714.5135, 2710348.195799998939037 ], [ 11135718.3693, 2710374.374699998646975 ], [ 11135728.987399999052, 2710393.814399998635054 ], [ 11135745.021, 2710432.977099999785 ], [ 11135763.813299998641, 2710471.075599998235703 ], [ 11135766.5482, 2710475.089499998837709 ], [ 11135777.856699999422, 2710477.6048 ], [ 11135800.2021, 2710475.247499998658895 ], [ 11135822.086399998516, 2710473.349599998444319 ], [ 11135833.691599998623, 2710477.866700001060963 ], [ 11135850.784499999136, 2710486.564599998295307 ], [ 11135859.96499999985, 2710486.146000001579523 ], [ 11135866.852299999446, 2710485.408799998462 ], [ 11135876.192899998277, 2710483.452100001275539 ], [ 11135885.97599999979, 2710485.0368 ], [ 11135887.9497, 2710488.277699999511 ], [ 11135885.9232, 2710496.4243 ], [ 11135876.51419999823, 2710513.15399999917 ], [ 11135861.4552, 2710527.702899999917 ], [ 11135838.7604, 2710539.4459 ], [ 11135821.300799999386, 2710543.826799999923 ], [ 11135799.121899999678, 2710543.261100001633167 ], [ 11135787.331599999219, 2710545.668000001460314 ], [ 11135778.42139999941, 2710553.782299999148 ], [ 11135776.703, 2710561.468699999154 ], [ 11135777.886799998581, 2710570.092 ], [ 11135785.4998, 2710577.8222 ], [ 11135792.034099999815, 2710587.239999998360872 ], [ 11135791.999899998307, 2710594.626600001007318 ], [ 11135787.83749999851, 2710601.532000001519918 ], [ 11135781.7, 2710605.504399999976 ], [ 11135764.693599998951, 2710611.118500001728535 ], [ 11135757.49599999934, 2710612.777499999851 ], [ 11135751.3092, 2710618.665699999779 ], [ 11135751.886199999601, 2710620.704199999571 ], [ 11135756.4697, 2710629.052799999714 ], [ 11135762.3581, 2710626.342500001192093 ], [ 11135771.8247, 2710624.699499998241663 ], [ 11135783.9367, 2710622.3508 ], [ 11135795.375399999321, 2710618.813700001686811 ], [ 11135812.5707, 2710613.006 ], [ 11135826.008299998939, 2710609.549800001084805 ], [ 11135851.452799998224, 2710603.026299998164177 ], [ 11135861.647199999541, 2710598.406100001186132 ], [ 11135867.913899999112, 2710594.055 ], [ 11135870.1077, 2710590.581399999559 ], [ 11135872.6108, 2710581.8321 ], [ 11135875.5995, 2710568.452399998903275 ], [ 11135877.586699999869, 2710563.255199998617172 ], [ 11135886.819899998605, 2710550.5513 ], [ 11135894.14499999955, 2710541.070199999958 ], [ 11135897.3896, 2710534.15509999916 ], [ 11135899.9545, 2710527.632199998944998 ], [ 11135903.672299999744, 2710518.5295 ], [ 11135908.056899998337, 2710512.2663 ], [ 11135915.550599999726, 2710504.9041 ], [ 11135925.9745, 2710497.0533 ], [ 11135933.9127, 2710493.9668 ], [ 11135943.2001, 2710492.466099999845 ], [ 11135960.657299999148, 2710491.794399999082 ], [ 11135971.080299999565, 2710491.250100001692772 ] ] ] } },',\n",
       " '{ \"type\": \"Feature\", \"id\": 1, \"properties\": { \"TBBH\": \"152\", \"DLMC\": \"园地\", \"TBMJ\": 174938.39, \"Shape_Leng\": 4122.6504550999998, \"Shape_Area\": 155888.70347199999 }, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 11138040.6565, 2710579.545099999756 ], [ 11138055.5876, 2710572.750300001353025 ], [ 11138069.8568, 2710566.6706 ], [ 11138094.3528, 2710552.8898 ], [ 11138105.1405, 2710553.206199999899 ], [ 11138110.1455, 2710562.312800001353025 ], [ 11138131.39499999955, 2710605.958500001579523 ], [ 11138148.260699998587, 2710635.157099999487 ], [ 11138158.47309999913, 2710630.6618 ], [ 11138177.5328, 2710629.680100001394749 ], [ 11138180.626699998975, 2710620.877599999309 ], [ 11138185.6799, 2710619.297699999064 ], [ 11138186.2993, 2710607.277899999171 ], [ 11138180.3693, 2710589.617600001394749 ], [ 11138185.999899998307, 2710585.101399999112 ], [ 11138182.73099999875, 2710581.346099998801947 ], [ 11138187.131099998951, 2710577.35869999975 ], [ 11138193.36699999869, 2710571.242199998348951 ], [ 11138198.3931, 2710560.845600001513958 ], [ 11138201.895799998194, 2710542.42689999938 ], [ 11138190.7364, 2710514.056099999696 ], [ 11138219.719, 2710499.2269 ], [ 11138236.715599998832, 2710536.173700001090765 ], [ 11138259.2604, 2710570.1343 ], [ 11138266.820099998266, 2710562.803399998694658 ], [ 11138272.00899999961, 2710560.124400001019239 ], [ 11138280.581799998879, 2710555.927299998700619 ], [ 11138286.274099998176, 2710553.97399999946 ], [ 11138293.909699998796, 2710552.67399999872 ], [ 11138305.145599998534, 2710554.203200001269579 ], [ 11138310.4759, 2710554.78539999947 ], [ 11138315.6611, 2710554.787599999458 ], [ 11138325.7478, 2710551.5335 ], [ 11138328.6094, 2710549.2489 ], [ 11138327.9664, 2710494.3352 ], [ 11138331.6198, 2710463.249000001698732 ], [ 11138338.9122, 2710452.68769999966 ], [ 11138364.192699998617, 2710441.776299998164177 ], [ 11138383.329399999231, 2710432.360899999738 ], [ 11138387.5909, 2710423.281599998474121 ], [ 11138383.909299999475, 2710392.73409999907 ], [ 11138382.803899999708, 2710325.802799999714 ], [ 11138390.2928, 2710314.110399998724461 ], [ 11138405.1688, 2710313.5711 ], [ 11138417.8277, 2710314.2357 ], [ 11138426.1398, 2710311.752599999309 ], [ 11138437.291799999774, 2710301.43299999833 ], [ 11138448.1169, 2710290.555199999362 ], [ 11138461.576099999249, 2710289.4644 ], [ 11138476.8498, 2710296.425700001418591 ], [ 11138488.481499999762, 2710312.899599999189 ], [ 11138486.271899998188, 2710362.3004 ], [ 11138486.25499999896, 2710392.306299999356 ], [ 11138480.781899999827, 2710422.309999998658895 ], [ 11138473.8557, 2710447.5568 ], [ 11138454.5504, 2710494.019299998879433 ], [ 11138437.25869999826, 2710512.222399998456 ], [ 11138428.270899999887, 2710525.7793 ], [ 11138430.068599998951, 2710537.314199998975 ], [ 11138445.0621, 2710547.075399998575449 ], [ 11138463.244399998337, 2710558.796 ], [ 11138489.0689, 2710565.397100001573563 ], [ 11138518.168099999428, 2710567.609000001102686 ], [ 11138543.267599999905, 2710570.550900001078844 ], [ 11138547.1185, 2710572.698199998587 ], [ 11138547.90529999882, 2710575.139499999583 ], [ 11138547.815099999309, 2710582.6796 ], [ 11138564.8337, 2710575.605399999768 ], [ 11138584.6961, 2710573.291099999 ], [ 11138613.4342, 2710568.612599998713 ], [ 11138629.640799999237, 2710537.694499999285 ], [ 11138642.4395, 2710533.047200001776218 ], [ 11138635.956399999559, 2710530.354699999094 ], [ 11138628.892499998212, 2710523.347399998456 ], [ 11138628.8621, 2710522.774399999529 ], [ 11138621.78029999882, 2710516.922200001776218 ], [ 11138609.792599998415, 2710511.06810000166297 ], [ 11138609.8018, 2710495.5339 ], [ 11138618.34789999947, 2710481.649 ], [ 11138626.1649, 2710472.333599999547 ], [ 11138674.141199998558, 2710443.848900001496077 ], [ 11138687.226399999112, 2710436.1807 ], [ 11138709.416099999, 2710411.814199998975 ], [ 11138707.035, 2710409.789 ], [ 11138687.9655, 2710393.572999998927116 ], [ 11138669.293499998748, 2710379.233399998396635 ], [ 11138665.99469999969, 2710376.699499998241663 ], [ 11138663.1955, 2710374.54199999943 ], [ 11138661.6409999989, 2710380.061 ], [ 11138661.635699998587, 2710388.833700001239777 ], [ 11138664.537, 2710398.5205 ], [ 11138663.6237, 2710409.11969999969 ], [ 11138653.9908, 2710417.338899999857 ], [ 11138627.0934, 2710434.6853 ], [ 11138596.746199999005, 2710450.202399998903275 ], [ 11138588.203899998218, 2710457.324799999595 ], [ 11138582.382899999619, 2710471.395199999213 ], [ 11138573.659, 2710477.786899998784065 ], [ 11138567.483399998397, 2710475.223900001496077 ], [ 11138566.039099998772, 2710457.861000001430511 ], [ 11138564.593699999154, 2710443.787599999458 ], [ 11138551.1612, 2710424.956399999559 ], [ 11138550.6229, 2710412.346900001168251 ], [ 11138562.249699998647, 2710412.900899998844 ], [ 11138571.3339, 2710411.4439 ], [ 11138593.499299999326, 2710408.167599998414516 ], [ 11138604.580899998546, 2710408.538499999791 ], [ 11138613.6644, 2710408.17790000140667 ], [ 11138621.2983, 2710401.786699999124 ], [ 11138626.208099998534, 2710393.565299998969 ], [ 11138630.03009999916, 2710380.591899998486042 ], [ 11138615.1451, 2710359.2012 ], [ 11138606.430799998343, 2710349.510499998927116 ], [ 11138592.4492, 2710335.613099999726 ], [ 11138583.9585, 2710326.736699998378754 ], [ 11138584.01949999854, 2710313.1468 ], [ 11138587.861699998379, 2710293.5511 ], [ 11138589.898099999875, 2710283.166499998420477 ], [ 11138586.149099998176, 2710251.465799998492002 ], [ 11138579.8944, 2710217.0896 ], [ 11138575.662399999797, 2710193.829300001263618 ], [ 11138568.810499999672, 2710146.246199999005 ], [ 11138563.09789999947, 2710144.942099999636 ], [ 11138546.362199999392, 2710158.658100001513958 ], [ 11138539.079799998552, 2710171.4842 ], [ 11138536.430399999022, 2710183.773400001227856 ], [ 11138535.347399998456, 2710203.5205 ], [ 11138520.4178, 2710201.592099998146296 ], [ 11138507.0681, 2710196.515099998563528 ], [ 11138459.7633, 2710229.61969999969 ], [ 11138409.069499999285, 2710252.009100001305342 ], [ 11138331.674199998379, 2710274.276799999177 ], [ 11138251.3799, 2710343.3616 ], [ 11138236.524, 2710360.405299998819828 ], [ 11138220.592099998146, 2710412.068999998271465 ], [ 11138200.3412, 2710460.9901 ], [ 11138138.555, 2710476.501899998635054 ], [ 11138091.477099999785, 2710471.929900001734495 ], [ 11138056.9858, 2710437.462699998170137 ], [ 11138050.144799999893, 2710393.863899998366833 ], [ 11138049.732, 2710374.479600001126528 ], [ 11138045.812399998307, 2710368.742199998348951 ], [ 11138039.351799998432, 2710366.049600001424551 ], [ 11138037.9285, 2710366.249299999326 ], [ 11138023.9224, 2710366.7901 ], [ 11138019.6475, 2710367.518699999899 ], [ 11138012.645599998534, 2710368.247499998658895 ], [ 11138006.9166, 2710367.5117 ], [ 11138003.875799998641, 2710364.788800001144409 ], [ 11137999.279699999839, 2710359.0269 ], [ 11137990.631799999624, 2710354.915699999779 ], [ 11137968.820099998266, 2710360.54399999976 ], [ 11137954.4169, 2710373.276399999857 ], [ 11137937.037399999797, 2710385.450199998915195 ], [ 11137924.29659999907, 2710389.7489 ], [ 11137899.804, 2710394.8187 ], [ 11137900.7888, 2710409.1369 ], [ 11137901.0559, 2710414.894000001251698 ], [ 11137898.6008, 2710422.659499999136 ], [ 11137892.14499999955, 2710430.879999998956919 ], [ 11137883.9693, 2710430.8746 ], [ 11137872.889499999583, 2710427.761100001633167 ], [ 11137863.536499999464, 2710423.827199999243 ], [ 11137855.635099999607, 2710420.258000001311302 ], [ 11137850.2782, 2710416.8746 ], [ 11137832.4303, 2710425.254599999636 ], [ 11137829.2758, 2710450.913800001144409 ], [ 11137854.5533, 2710504.822299998253584 ], [ 11137873.632599998266, 2710585.59899999946 ], [ 11137926.2351, 2710643.911899998784065 ], [ 11137963.16059999913, 2710675.256499998271465 ], [ 11138016.61439999938, 2710679.780000001192093 ], [ 11138053.5095, 2710701.905900001525879 ], [ 11138057.063499998301, 2710701.800299998372793 ], [ 11138035.73409999907, 2710668.573600001633167 ], [ 11138026.095699999481, 2710648.758900001645088 ], [ 11137995.9004, 2710601.598900001496077 ], [ 11138012.6633, 2710594.7291 ], [ 11138033.4987, 2710582.80180000141263 ], [ 11138040.6565, 2710579.545099999756 ] ], [ [ 11138004.3495, 2710393.0251 ], [ 11138008.4338, 2710397.321699999273 ], [ 11138012.789299998432, 2710405.09259999916 ], [ 11138023.855399999768, 2710432.877300001680851 ], [ 11138025.2967, 2710452.706599999219 ], [ 11138021.9325, 2710459.4666 ], [ 11138020.202199999243, 2710466.226599998772144 ], [ 11138021.648499999195, 2710477.650899998844 ], [ 11138021.920099999756, 2710481.488699998706579 ], [ 11138021.189599998295, 2710487.519099999219 ], [ 11138018.5535, 2710490.441599998623133 ], [ 11138007.199099998921, 2710490.708099998533726 ], [ 11138001.657099999487, 2710491.61899999902 ], [ 11137995.478, 2710495.270100001245737 ], [ 11137989.208599999547, 2710498.921999998390675 ], [ 11137982.9382, 2710503.03009999916 ], [ 11137976.214499998838, 2710506.59010000154376 ], [ 11137972.3982, 2710508.780499998480082 ], [ 11137968.310199998319, 2710510.6972 ], [ 11137965.403299998492, 2710511.243900001049042 ], [ 11137962.497499998659, 2710508.501200001686811 ], [ 11137962.956199999899, 2710500.5513 ], [ 11137971.4336, 2710451.212099999189 ], [ 11137972.1711, 2710431.657699998468161 ], [ 11137970.000799998641, 2710415.666900001466274 ], [ 11137968.3753, 2710399.491599999368 ], [ 11137988.543, 2710395.391499999911 ], [ 11138000.080499999225, 2710391.743500001728535 ], [ 11138004.3495, 2710393.0251 ] ] ] } },']"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdd2.take(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按地类名称进行统计一下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "def myMap(line):\n",
    "    if line[-1:] == \",\":\n",
    "            line = line[:-1]\n",
    "    dt = json.loads(line)\n",
    "    geojson = json.dumps(dt[\"geometry\"])\n",
    "    return (dt[\"properties\"][\"DLMC\"],\n",
    "                ogr.CreateGeometryFromJson(geojson).GetArea())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('旱地', 1062114.5405702349),\n",
       " ('园地', 974189.4862148697),\n",
       " ('农村居民点用地', 39557.91353731044),\n",
       " ('其他独立建设用地', 257737.88656521734),\n",
       " ('林地', 4250805.430876931)]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rdd2.map(lambda js:myMap(js)).reduceByKey(lambda x,y : x+y).collect()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
